﻿@{
    ViewBag.Title = "轨迹测试";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head{
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script>
}
  <div style="text-align:center;font-size:30px;width:100%;height:30px;color:blue;margin-bottom:20px;">轨迹查看</div>

<div>
    <table cellpadding="5">
        <tr>
            <td>IMEI号：</td>
            <td><input class="easyui-textbox" type="text" id="QIMEI" data-options="prompt:'IMEI号'" /></td>
            <td>开始时间</td>
            <td><input class="easyui-datetimebox" type="text" id="start" data-options="required:true,editable:false" /></td>
            <td>结束时间</td>
            <td><input class="easyui-datetimebox" type="text" id="end" data-options="required:true,editable:false" /></td>
            <td><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="Find();" style="width:60px">查询</a></td>
        </tr>


    </table>
    <input type="submit" name="BtnSave" value="Save Employee" />
    @using (Html.BeginForm("TestMethod", "Trace", FormMethod.Post))
    {
        <table cellpadding="5">
            <tr>
                <td>IMEI号：</td>
                <td><input class="easyui-textbox" type="text" id="QIMEI" data-options="prompt:'IMEI号'" /></td>
                <td>开始时间</td>
                <td><input class="easyui-datetimebox" type="text" id="start" data-options="required:true,editable:false" /></td>
                <td>结束时间</td>
                <td><input class="easyui-datetimebox" type="text" id="end" data-options="required:true,editable:false" /></td>
                <td><input type="submit" id="submit" value="搜 索"></td>
            </tr>


        </table>
    }
    @Html.ActionLink("aaaa", "GetOrbit", "Trace", new { id=1})
</div>
@*查看轨迹*@
<div id="guiji" style="width:100%;height:600px;padding:10px;">
    <div id="guijimap" style="width: 100%;height: 550px;"></div>
</div>


<script type="text/javascript">
    var map = new BMap.Map("guijimap");


    //查看点位置
    function Find() {
        //var tempValue;
        //var tempText;
        //tempValue = $("#driverID").combobox("getValue");
        //tempText = $("#driverID").combobox("getText");
        //if (isNaN(tempValue) || !isNaN(tempText)) {
        //    alert("运输单位输入有误！");
        //    return;
        //}
        //tempValue = $("#truckID").combobox("getValue");
        //tempText = $("#truckID").combobox("getText");
        //if (isNaN(tempValue) || !isNaN(tempText)) {
        //    alert("车牌号选择有误！");
        //    return;
        //}



        var IMEI = $("#QIMEI").val();
        var cc = [];
        // 百度地图API功能
        //var IMEI = $("#IMEI").val();
        var start = $("#start").datetimebox("getValue");
        var end = $("#end").datetimebox("getValue");
        if (end < start) {
            alert("时间输入有误");
            return;
        }

        // 创建Map实例
        map.centerAndZoom(new BMap.Point(106.534083, 29.464074), 12);  // 初始化地图,设置中心点坐标和地图级别
        map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
        map.setCurrentCity("重庆");          // 设置地图显示的城市 此项是必须设置的
        map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
        map.clearOverlays();
        map.addControl(new BMap.ScaleControl());
        $.ajax({
            type: "POST",
            url: "/Trace/GetOrbit",
            async: false,
            data: { "IMEI": IMEI, "start": start, "end": end },
            success: function (msg) {
                if (msg == 0) {
                    alert("查询不到该车的GPS记录");
                }
                else {
                    for (var i = 0; i < msg.length; i++) {
                        //console.log(msg[i].Longitude + "     " + msg[i].Latitude);
                        if (i == 0) {
                            map.centerAndZoom(new BMap.Point(msg[i].Longitude, msg[i].Latitude), 13);
                        }
                        cc.push(new BMap.Point(msg[i].Longitude, msg[i].Latitude));
                    }
                    var polyline = new BMap.Polyline(cc, { strokeColor: "blue", strokeWeight: 5, strokeOpacity: 0.5 });   //创建折线
                    map.addOverlay(polyline);   //增加折线
                }
            }
        });

    }


</script>

